#include<iostream>
#include<vector>
using namespace std;
vector<int> merge(vector<int>& v1, vector<int>& v2)
{
	int ans1 = 0;
	int ans2 = 0;
	vector<int> v;
	while (ans1 < v1.size() && ans2 < v2.size())
	{
		while (ans1 < v1.size() && ans2 < v2.size() && v1[ans1] <= v2[ans2])
		{
			v.push_back(v1[ans1++]);
		}
		while (ans1 < v1.size() && ans2 < v2.size() && v1[ans1] >= v2[ans2])
		{
			v.push_back(v2[ans2++]);
		}
	}
	while (ans1 < v1.size())
	{
		v.push_back(v1[ans1++]);
	}
	while (ans2 < v2.size())
	{
		v.push_back(v2[ans2++]);
	}
	return v;
}
int main()
{
	vector<int> v1;
	vector<int> v2;
	v1 = { 1,2,3,4,5,9 };
	v2 = { 2,3,4,5,6,7,10,22 };
	vector<int> v = merge(v1, v2);
	for (auto i : v)
	{
		cout << i << ' ';
	}
}